<template>
	<view class="tn-safe-area-inset-bottom">
		<!-- 顶部自定义导航 -->
    <tn-nav-bar  fixed customBack :bottomShadow="false" backgroundColor="#FFFFFF">
      <view slot="back" class='tn-custom-nav-bar__back'
        @click="goBack">
        <text class='icon tn-icon-left'></text>
        <text class='icon tn-icon-home-capsule-fill'></text>
      </view>
			<view class="tn-flex tn-flex-col-center tn-flex-row-center ">
				<text class="tn-text-bold tn-text-xl tn-color-black">壁纸搜索</text>
			</view>
    </tn-nav-bar>

		<view class="tn-search-fixed" v-if="showSearch">
			<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-margin"
				:style="{marginTop: vuex_custom_bar_height + 'px'}">

				<view class="justify-content-item align-content-item" style="width: 100vw;">
					<view class="tn-flex tn-flex-col-center"
						style="border-radius: 100rpx;padding: 10rpx 20rpx 10rpx 20rpx;width: 90%;background-color: rgba(248, 247, 248, 0.9);">
						<text class="tn-icon-search justify-content-item tn-padding-right-xs tn-color-gray tn-text-lg"></text>
						<input class="justify-content-item" :placeholder="searchWhere.title" @input="searchInput" name="input"
							placeholder-style="color:#AAAAAA" style="width: 90%;" confirm-type="search"></input>
					</view>
				</view>

				<view class="align-content-item">
					<view class="justify-content-item tn-text-center">
						<tn-button backgroundColor="#3668fc" shape="round" padding="20rpx 20rpx" width="150rpx" @click="getImageList">
							<text class="tn-color-white">搜 索</text>
						</tn-button>

					</view>
				</view>
			</view>
		</view>

<!-- 		<view class="" style="margin-top: 160rpx;" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<view class="tn-flex tn-flex-row-between tn-margin">
				<view class="justify-content-item tn-text-bold">
					<text class="tn-text-df tn-color-black">热门搜索</text>
				</view>
				<view class="justify-content-item tn-text-df tn-color-grey" @click="clearSearch">
					<text class="tn-padding-xs">清空搜索</text>
					<text class="tn-icon-delete"></text>
				</view>
			</view>
		</view> -->

		<!-- <view class="">
			<view class="tn-tag-search tn-margin tn-text-justify">
				<view v-for="(item, index) in tagList" :key="index"
					class="tn-tag-search__item tn-margin-right tn-round tn-text-sm tn-bg-gray--light tn-color-gray"  @click="clickSearch(item.title)" :style="'color:' + item.color +' !important;'">
					<text class="tn-tag-search__item--prefix">#</text> {{ item.title }}
				</view>
			</view>
		</view> -->

		<view style="margin-top: 160rpx;" class="tn-flex tn-flex-row-between tn-margin" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
		<!-- 	<view class="justify-content-item tn-text-bold">
				<text class="tn-text-df tn-color-black">搜索结果</text>
			</view> -->
			<!-- <view class="justify-content-item tn-text-df tn-color-grey">
				<text class="tn-padding-xs">筛选</text>
				<text class="tn-icon-filter"></text>
			</view> -->
		</view>


		<!-- 不建议写时间，因为写了时间，你就要经常更新文章了鸭-->
		<view class="tn-margin-bottom-lg">
			<block v-for="(item, index) in imageArray" :key="index">
				<view class="article-shadow tn-margin" @click="tn('/pageA/details/details?image_uid=' + item.uid + '&device_type=' + item.device_type)">
					<view class="tn-flex">
						<view class="tn-margin-sm tn-padding-top-xs" style="width: 100%;">
							<view class="tn-text-lg tn-text-bold clamp-text-1 tn-text-justify">
								<text class="">{{ item.title }}</text>
							</view>
							<view class="tn-padding-top-xs" style="min-height: 90rpx;">
								<text class="tn-text-df tn-color-gray clamp-text-2 tn-text-justify">
										<!-- 这里放壁纸描述 -->
								</text>
							</view>
							<view class="tn-flex tn-flex-row-between tn-flex-col-between">
								<view class="justify-content-item tn-color-gray tn-text-center" :style="'padding-top: 15rpx;color:'+ item.series.bg_color + ';'">
									<block v-if="item.device_type == 1">
										<text class="tn-icon-phone tn-padding-right-xs tn-text-lg"></text>
										<text class="tn-padding-right tn-text-df">
											手机壁纸
										</text>
									</block>
									<block v-if="item.device_type == 2">
										<text class="tn-icon-computer tn-padding-right-xs tn-text-lg"></text>
										<text class="tn-padding-right tn-text-df">
											电脑壁纸
										</text>
									</block>
									<block v-if="item.device_type == 3">
										<text class="tn-icon-ipad tn-padding-right-xs tn-text-lg"></text>
										<text class="tn-padding-right tn-text-df">
											平板壁纸
										</text>
									</block>
									<text class="tn-icon-download tn-padding-right-xs tn-text-lg"></text>
									<text class="tn-text-df">{{ item.download }}</text>
								</view>
							</view>
						</view>
						<view class="image-pic tn-margin-sm" :style="'background-image:url(' + item.url + item.path + ')'">
							<view class="image-article">
							</view>
						</view>
					</view>
				</view>
			</block>
		</view>
		
		<!-- 回到首页悬浮按钮-->
		<view v-if="show">
			<nav-index-button></nav-index-button>
		</view>

	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import { imageList } from '@/utils/api/image.js'
	import NavIndexButton from '@/libs/components/nav-index-button.vue'
	export default {
		name: 'TemplateSearch',
		mixins: [template_page_mixin],
		components: { NavIndexButton },
		data() {
			return {
				showSearch: true,
				show: false,
				imageArray: [],
				searchWhere: {
					page: 1,
					size: 20,
					title: "",
					type: 1,
					series_uid: '',
				},
			}
		},
		onLoad(params) {
			this.searchWhere.series_uid = params.uid || ""
			this.getImageList()
		},
		methods: {
			getImageList() {
				imageList(this.searchWhere).then(res => {
					if (this.searchWhere.page == 1) {
						this.imageArray = []
					}
					if (res.items.length == 0) {
						this.$func.showToast("无更多壁纸")
					}
					this.imageArray.push(...res.items)
					this.searchWhere.type = -1
					this.searchWhere.page = res.page + 1
				})
			},
			searchInput(e) {
				// 清空原数据以及查询条件
				this.searchWhere.page = 1
				this.searchWhere.size = 20
				this.imageArray = []
				this.searchWhere.title = e.detail.value
			},
			clickSearch(title) {
				this.searchWhere.page = 1
				this.searchWhere.title = title
				this.getImageList()
			},
			clearSearch () {
				this.searchWhere.title = ""
				this.searchWhere.page = 1
				this.searchWhere.size = 20
				this.getImageList()
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
		},
		onReachBottom() {
			this.getImageList()
		},
		onPageScroll(e) {
			if (e.scrollTop > 50) {
				this.showSearch = false
			} else {
				this.showSearch = true
			}
			if (e.scrollTop > 1000) {
				this.show = true
			} else {
				this.show = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}

	.tn-search-fixed {
		position: fixed;
		top: 50rpx;
		width: 100%;
		transition: all 0.25s ease-out;
		z-index: 1;
	}


	/* 搜索标签 start*/
	.tn-tag-search {
		&__item {
			display: inline-block;
			line-height: 45rpx;
			padding: 10rpx 30rpx;
			margin: 20rpx 20rpx 5rpx 0rpx;

			&--prefix {
				padding-right: 10rpx;
			}
		}
	}

	/* 标签内容 end*/

	/* 标题 start */
	.nav_title {
		-webkit-background-clip: text;
		color: transparent;

		&--wrap {
			position: relative;
			display: flex;
			height: 120rpx;
			font-size: 42rpx;
			align-items: center;
			justify-content: center;
			font-weight: bold;
			background-image: url(https://tnuiimage.tnkjapp.com/title_bg/title00.png);
			background-size: cover;
		}
	}

	/* 标题 end */

	/* 富文本图示意 start */
	.news-img {
		z-index: -1;
		padding-bottom: 40rpx;

		image {
			width: 100%;
			margin: 20rpx 0;
			// height: 3373rpx;
			// z-index: -1;
		}
	}

	/* 资讯主图 start*/
	.image-article {
		border-radius: 8rpx;
		border: 1rpx solid #F8F7F8;
		width: 200rpx;
		height: 100%;
		position: relative;
	}

	.image-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
	}

	.article-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	/* 文字截取*/
	.clamp-text-1 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.clamp-text-2 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	/* 标签内容 start*/
	.tn-tag-content {
		&__item {
			display: inline-block;
			line-height: 35rpx;
			padding: 7rpx 25rpx 5rpx 25rpx;

			&--prefix {
				padding-right: 10rpx;
			}
		}
	}

	/* 标签内容 end*/
</style>